//
//  RGBColor.m
//  MyFunctionDemo
//
//  Created by Ting Han on 2017/9/1.
//  Copyright © 2017年 Ting Han. All rights reserved.
//

#import "RGBColorConfig.h"

@implementation RGBColorConfig

+ (instancetype)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha{
    RGBColorConfig *config = [[self class]new];
    config.red = red;
    config.blue = blue;
    config.green = green;
    config.alpha = alpha;
    return config;
}

+ (instancetype)colorWithUIColor:(UIColor *)color{
    RGBColorConfig *config = [[[self class]alloc]init];
    CGFloat red = 0;
    CGFloat blue = 0;
    CGFloat green = 0;
    CGFloat alpha = 0;
    [color getRed:&red green:&green blue:&blue alpha:&alpha];
    config.red = red;
    config.blue = blue;
    config.green = green;
    config.alpha = alpha;
    return config;
}

+ (instancetype)randomColor{
    RGBColorConfig *config = [[[self class]alloc]init];
    
    config.red = arc4random()%256/255.f;
    config.blue = arc4random()%256/255.f;
    config.green = arc4random()%256/255.f;
    config.alpha = arc4random()%256/255.f;
    
    return config;
}
+ (instancetype)randomColorWithAlpha:(CGFloat)alpha{
    RGBColorConfig *config = [[[self class]alloc]init];
    
    config.red = arc4random()%256/255.f;
    config.blue = arc4random()%256/255.f;
    config.green = arc4random()%256/255.f;
    config.alpha = (alpha < 0 || alpha >1)?1:alpha;
    
    return config;
}


@end
